package com.huirui.server.controller.mini.program;

import com.huirui.server.pojo.entity.Brand;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.BrandDetailVo;
import com.huirui.server.pojo.vo.BrandWithLetterVo;
import com.huirui.server.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/brand")
@Slf4j
@Validated
@Tag(name = "品牌管理", description = "微信小程序用户品牌查询相关")
@RequiredArgsConstructor
public class BrandController {

    private final BrandService brandService;

    @GetMapping("/list")
    @Operation(summary = "获取品牌列表")
    public Result<PageResult<Brand>> listBrand(@RequestParam(value = "brandName", required = false) String brandName, int page, int pageSize) {
        PageResult<Brand> res = brandService.listBrand(brandName, page, pageSize);
        return Result.success(res);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "获取品牌详细信息")
    public Result<BrandDetailVo> detailBrand(@PathVariable("id") Long brandId) {
        BrandDetailVo brandDetailVo = brandService.getBrandDetailInfo(brandId);
        return Result.success(brandDetailVo);
    }

    @GetMapping("/list/with/letter")
    @Operation(summary = "获取包装字母排序的品牌信息")
    public Result<List<BrandWithLetterVo>> listBrandWithLetter() {
        List<BrandWithLetterVo> list = brandService.listBrandWithLetter();
        return Result.success(list);
    }


}
